package com.frogs.ucenter.v1.service.impl;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.frogs.framework.util.PageList;
import com.frogs.framework.util.StringUtil;
import com.frogs.system.util.ShippingAddressStatusEnum;
import com.frogs.system.web.api.request.Request;
import com.frogs.system.web.api.response.Response;
import com.frogs.system.web.exception.RequestIllegalException;
import com.frogs.system.web.exception.ServiceOperationException;
import com.frogs.ucenter.dao.UserShippingAddressDao;
import com.frogs.ucenter.dao.UserShippingAddressTemporaryDao;
import com.frogs.ucenter.entity.FollowedShippingAddressWithAreaCode;
import com.frogs.ucenter.entity.UserShippingAddress;
import com.frogs.ucenter.entity.UserShippingAddressTemporary;
import com.frogs.ucenter.entity.UserShippingAddressWithAreaCode;
import com.frogs.ucenter.v1.request.FollowedShippingAddressAddRequest;
import com.frogs.ucenter.v1.request.FollowedShippingAddressDeleteRequest;
import com.frogs.ucenter.v1.request.FollowedShippingAddressListRequest;
import com.frogs.ucenter.v1.request.FollowedShippingAddressUpdateRequest;
import com.frogs.ucenter.v1.request.UserShippingAddressAddRequest;
import com.frogs.ucenter.v1.request.UserShippingAddressDefaultRequest;
import com.frogs.ucenter.v1.request.UserShippingAddressDeleteRequest;
import com.frogs.ucenter.v1.request.UserShippingAddressListRequest;
import com.frogs.ucenter.v1.request.UserShippingAddressShowDefaultRequest;
import com.frogs.ucenter.v1.request.UserShippingAddressShowRequest;
import com.frogs.ucenter.v1.request.UserShippingAddressUpdateRequest;
import com.frogs.ucenter.v1.response.AddResponse;
import com.frogs.ucenter.v1.response.DeleteResponse;
import com.frogs.ucenter.v1.response.PageListResponse;
import com.frogs.ucenter.v1.response.ShowResponse;
import com.frogs.ucenter.v1.response.UpdateResponse;
import com.frogs.ucenter.v1.service.UserShippingAddressService;
import com.frogs.ucenter.v1.util.ApiConstants;

@Transactional(propagation=Propagation.REQUIRED, rollbackFor=Exception.class) 
@Service(ApiConstants.VERSION+"userShippingAddressService")
public class UserShippingAddressServiceImpl extends UserBaseServiceImpl implements UserShippingAddressService {
    @Resource
    private UserShippingAddressDao userShippingAddressDao;
    @Resource
    private UserShippingAddressTemporaryDao userShippingAddressTemporaryDao;
    
    private static final Logger log = LoggerFactory.getLogger(UserShippingAddressServiceImpl.class);
    
    /**
     * 获取列表,仅获取状态生效的地址
     */
    @Override
    public Response getPageList(Request request) throws Exception {
    	PageListResponse<UserShippingAddressWithAreaCode> response = new PageListResponse<UserShippingAddressWithAreaCode>();
        
    	try {
    		UserShippingAddressListRequest listRequest = (UserShippingAddressListRequest)request;
	    	Map<String, Object> params = new HashMap<String , Object>();
	    	params.put("eqUserId", listRequest.getUserId());
	    	params.put("eqStatus", ShippingAddressStatusEnum.STATUS_NOT_DELETE.getId());
	    	if(!StringUtil.isEmpty(listRequest.getAreaId())) {
	    		params.put("eqAreaId", listRequest.getAreaId());
	    	}
	        PageList<UserShippingAddressWithAreaCode> list = userShippingAddressDao.selectByMap( params , listRequest.getPageNum(), listRequest.getNumPerPage()); 
	        for(int i = 0; i< list.size(); i++) {
	        	UserShippingAddressWithAreaCode addr = list.get(i);
	        	parseAddressArea(addr);
	        }
	        
	        response.setList(list);
	        response.setPageTurn(list.getPageTurn());
	        response.setTip("用户收货地址查询成功");
	    } catch (Exception e) {
	    	log.error("func[{}] request[{}] exception[{}] desc[fail]",
					new Object[] { this.getClass().getName() +"."+Thread.currentThread().getStackTrace()[1].getMethodName(),
						request,Arrays.deepToString(e.getStackTrace()) });
			throw new ServiceOperationException("请求处理失败：" + e.getMessage());
		}
	    return response;
    }
    
    /**
     * 查询用户地址
     * @param request
     * @return
     */
    @Override
    public Response getObject(Request request) throws Exception {
    	ShowResponse<UserShippingAddressWithAreaCode> response = new ShowResponse<UserShippingAddressWithAreaCode>();
    	
    	try {
    		UserShippingAddressShowRequest showRequest = (UserShippingAddressShowRequest)request;
    		UserShippingAddressWithAreaCode userShippingAddress = userShippingAddressDao.selectById(showRequest.getId());
	    	if (userShippingAddress == null ) {
	    		throw new ServiceOperationException(showRequest.getId() + "该收货地址不存在");
	    	}
    		if(userShippingAddress.getUserId().intValue() != showRequest.getUserId()){
	    		throw new RequestIllegalException("error userId:"+showRequest.getUserId());
	    	}
	    	
	    	parseAddressArea(userShippingAddress);
	    	response.setInfo(userShippingAddress);
	    	response.setTip("用户收货地址查询成功");
	    } catch (Exception e) {
	    	log.error("func[{}] request[{}] exception[{}] desc[fail]",
					new Object[] { this.getClass().getName() +"."+Thread.currentThread().getStackTrace()[1].getMethodName(),
						request,Arrays.deepToString(e.getStackTrace()) });
			throw new ServiceOperationException("请求处理失败：" + e.getMessage());
		}
	    return response;
    }
    
    /**
     * 添加用户地址,若当前无默认地址，将地址设为默认地址
     * @param request
     * @return
     */
    @Override
    public Response insert(Request request) throws Exception {
    	AddResponse<UserShippingAddressWithAreaCode> response = new AddResponse<UserShippingAddressWithAreaCode>();
    	
    	try {
	    	UserShippingAddressAddRequest addRequest = (UserShippingAddressAddRequest)request;
	    	UserShippingAddressWithAreaCode object = new UserShippingAddressWithAreaCode();
	    	object.setCity(addRequest.getCity());
	    	object.setContactNumber(addRequest.getContactNumber());
	    	object.setContacts(addRequest.getContacts());
	    	object.setDistrict(addRequest.getDistrict());
	    	object.setFullAddress(addRequest.getFullAddress());
	    	object.setIsPrivacyReceipt(addRequest.getIsPrivacyReceipt());
	    	object.setIsTemporaryAddress(addRequest.getIsTemporaryAddress());
	    	object.setPostcode(addRequest.getPostcode());
	    	object.setProvince(addRequest.getProvince());
	    	object.setRank(addRequest.getRank());
	    	object.setStatus(addRequest.getStatus());
	    	object.setStreet(addRequest.getStreet());
	    	object.setUserId(addRequest.getUserId());
	    	object.setAreaId(addRequest.getAreaId());
	    	object.setTelNumber(addRequest.getTelNumber());
	    	object.setName(addRequest.getName());
	    	
	    	UserShippingAddressWithAreaCode address = getDefaultAddress(addRequest.getUserId());
	    	if(null == address || address.getIsDefault() == ShippingAddressStatusEnum.STATUS_NOT_DEFAULT.getId()) {
	    		object.setIsDefault(ShippingAddressStatusEnum.STATUS_DEFAULT.getId());
	    	} else {
	    		object.setIsDefault(addRequest.getIsDefault());
	    	}
	    	
	    	if(null != address && addRequest.getIsDefault() == ShippingAddressStatusEnum.STATUS_DEFAULT.getId()) {
	    		address.setIsDefault(ShippingAddressStatusEnum.STATUS_NOT_DEFAULT.getId());
	    		userShippingAddressDao.update(address);
	    	}
	    	
	    	userShippingAddressDao.insert(object);
	    	response.setInfo(object);
	    	response.setTip("用户收货地址新增成功");
	    } catch (Exception e) {
	    	log.error("func[{}] request[{}] exception[{}] desc[fail]",
					new Object[] { this.getClass().getName() +"."+Thread.currentThread().getStackTrace()[1].getMethodName(),
						request,Arrays.deepToString(e.getStackTrace()) });
			e.printStackTrace();
	    	throw new ServiceOperationException("请求处理失败：" + e.getMessage());
		}
	    return response;
    }
    

    /**
     * 修改用户地址
     * @param request
     * @return
     */
    @Override
    public Response update(Request request) throws Exception {
    	UpdateResponse<UserShippingAddress> response = new UpdateResponse<UserShippingAddress>();
    	
    	try {
	    	UserShippingAddressUpdateRequest updateRequest = (UserShippingAddressUpdateRequest)request;
	    	UserShippingAddressWithAreaCode object = userShippingAddressDao.selectById(updateRequest.getId());
	    	//修改地址以后将地址归类为官网地址
	    	if(object.getUserId().intValue() != updateRequest.getUserId()){
	    		throw new RequestIllegalException("error userId:"+updateRequest.getUserId());
	    	}
	    	
	    	//object.setSource(OrderProduceSourceEnum.EHY.getCode());
	    	object.setId(updateRequest.getId());
	    	object.setCity(updateRequest.getCity());
	    	object.setContactNumber(updateRequest.getContactNumber());
	    	object.setContacts(updateRequest.getContacts());
	    	object.setDistrict(updateRequest.getDistrict());
	    	object.setFullAddress(updateRequest.getFullAddress());
	    	object.setIsDefault(updateRequest.getIsDefault());
	    	object.setIsPrivacyReceipt(updateRequest.getIsPrivacyReceipt());
	    	object.setIsTemporaryAddress(updateRequest.getIsTemporaryAddress());
	    	object.setPostcode(updateRequest.getPostcode());
	    	object.setProvince(updateRequest.getProvince());
	    	object.setRank(updateRequest.getRank());
	    	object.setStatus(updateRequest.getStatus());
	    	object.setStreet(updateRequest.getStreet());
	    	object.setUserId(updateRequest.getUserId());
	    	object.setAreaId(updateRequest.getAreaId());
	    	object.setTelNumber(updateRequest.getTelNumber());
	    	object.setName(updateRequest.getName());
	    	
	    	userShippingAddressDao.update(object);
	    	response.setInfo(object);
	    	response.setTip("用户收货地址修改成功");
	    } catch (Exception e) {
	    	log.error("func[{}] request[{}] exception[{}] desc[fail]",
					new Object[] { this.getClass().getName() +"."+Thread.currentThread().getStackTrace()[1].getMethodName(),
						request,Arrays.deepToString(e.getStackTrace()) });
			throw new ServiceOperationException("请求处理失败：" + e.getMessage());
		}
	    return response;
    }
    
    /**
     * 删除用户地址
     * @param request
     * @return
     */
    @Override
    public Response delete(Request request) throws Exception {
    	DeleteResponse<UserShippingAddress> response = new DeleteResponse<UserShippingAddress>();
    	int isDeleteDefault = ShippingAddressStatusEnum.STATUS_NOT_DEFAULT.getId();
    	
    	try {
	    	UserShippingAddressDeleteRequest deleteRequest = (UserShippingAddressDeleteRequest)request;
	    	UserShippingAddressWithAreaCode object = userShippingAddressDao.selectById(deleteRequest.getId());
	    	if(object.getUserId().intValue() != deleteRequest.getUserId()){
	    		throw new RequestIllegalException("非法操作，该地址非当前用户所有！userId" + deleteRequest.getUserId());
	    	}
	    	
	    	isDeleteDefault = object.getIsDefault(); 
	    	object.setStatus(ShippingAddressStatusEnum.STATUS_DELETE.getId());
	    	userShippingAddressDao.update(object);
	    	
	    	//删除的地址如果为默认地址，默认将第一个
	    	if(isDeleteDefault == ShippingAddressStatusEnum.STATUS_DEFAULT.getId()) {
		    	Map<String,Object> params = new HashMap<String,Object>();
		    	params.put("eqUserId", deleteRequest.getUserId());
		    	params.put("eqStatus", ShippingAddressStatusEnum.STATUS_NOT_DELETE.getId());
		    	
		    	PageList<UserShippingAddressWithAreaCode> addressList = userShippingAddressDao.selectByMap(params, 1, 1);
		    	if(null != addressList && addressList.size() > 0) {
		    		params.clear();
		    		params.put("eqId", addressList.get(0).getId());
		    		params.put("isDefault",ShippingAddressStatusEnum.STATUS_DEFAULT.getId());
			    	userShippingAddressDao.updateByMap(params);
		    	 }
	    	}
	    	
	    	response.setTip("用户收货地址删除成功");
	    } catch (Exception e) {
	    	log.error("func[{}] request[{}] exception[{}] desc[fail]",
					new Object[] { this.getClass().getName() +"."+Thread.currentThread().getStackTrace()[1].getMethodName(),
						request,Arrays.deepToString(e.getStackTrace()) });
			throw new ServiceOperationException("请求处理失败：" + e.getMessage());
		}
	    return response;
    }
    
    /**
     * 设置默认地址
     * 思路：由于默认地址仅有一个，所以在切换默认地址之前，先将所有地址取消默认，然后将制定地址设置默认
     */
    @Override
	public Response setDefault(Request request) throws Exception {
    	
    	UserShippingAddressDefaultRequest usadr = (UserShippingAddressDefaultRequest) request;
    	UpdateResponse<UserShippingAddress> response = new UpdateResponse<UserShippingAddress>();
    	Map<String,Object> addrMap = new HashMap<String,Object>();
    	
    	try {
    		
    		UserShippingAddress address = userShippingAddressDao.selectById(usadr.getId());
    		if(usadr.getUserId() != address.getUserId()) {
    			throw new Exception("该地址不属于该用户，请确认！");
    		}
    		if(address.getStatus() == ShippingAddressStatusEnum.STATUS_DELETE.getId()) {
    			throw new Exception("该地址不可用，请确认!");
    		}
    		//若该地址已默认，不需要对地址做修改，直接返回
    		if(address.getIsDefault() != ShippingAddressStatusEnum.STATUS_DEFAULT.getId()){
    		
		    	//清空所有地址默认状态
		    	addrMap.put("eqUserId", usadr.getUserId());
		    	addrMap.put("isDefault", ShippingAddressStatusEnum.STATUS_NOT_DEFAULT.getId());
		    	userShippingAddressDao.updateByMap(addrMap);
		    	
		    	//设置默认地址
		    	addrMap.put("eqId", usadr.getId());
		    	addrMap.put("isDefault",ShippingAddressStatusEnum.STATUS_DEFAULT.getId());
		    	userShippingAddressDao.updateByMap(addrMap);
    		}
	    	
	    	response.setTip("设置默认地址成功！");
    	} catch (Exception e) {
    		log.error("func[{}] request[{}] exception[{}] desc[fail]",
					new Object[] { this.getClass().getName() +"."+Thread.currentThread().getStackTrace()[1].getMethodName(),
						request,Arrays.deepToString(e.getStackTrace()) });
			throw new ServiceOperationException("请求处理失败：" + e.getMessage());
		}
		return response;
	}
    
    /**
     * 获取默认收货地址，如果用户不存在默认收货地址，取用户第一个收货地址,若无合适的地址，返回空
     */
    @Override
	public Response showDefault(Request request) throws Exception {
    	try{
	    	UserShippingAddressShowDefaultRequest defaultRequest = (UserShippingAddressShowDefaultRequest) request;
	    	ShowResponse<UserShippingAddressWithAreaCode> response = new ShowResponse<UserShippingAddressWithAreaCode>();
	    	UserShippingAddressWithAreaCode address = getDefaultAddress(defaultRequest.getUserId());
	    	response.setInfo(address);
			return response;
    	}catch(Exception e){
    		log.error("func[{}] request[{}] exception[{}] desc[fail]",
					new Object[] { this.getClass().getName() +"."+Thread.currentThread().getStackTrace()[1].getMethodName(),
						request,Arrays.deepToString(e.getStackTrace()) });
			throw new ServiceOperationException("请求处理失败：" + e.getMessage());
		}
	}

	@Override
	public Response getFollowedPageList(Request request) throws Exception {
		PageListResponse<FollowedShippingAddressWithAreaCode> response = new PageListResponse<FollowedShippingAddressWithAreaCode>();
        
    	try {
    		FollowedShippingAddressListRequest listRequest = (FollowedShippingAddressListRequest)request;
	    	Map<String, Object> params = new HashMap<String , Object>();
	    	params.put("eqUserId", listRequest.getUserId());
	    	params.put("eqStatus", ShippingAddressStatusEnum.STATUS_NOT_DELETE.getId());
	    	if(!StringUtil.isEmpty(listRequest.getAreaId())) {
	    		params.put("eqAreaId", listRequest.getAreaId());
	    	}
	        PageList<FollowedShippingAddressWithAreaCode> list = userShippingAddressTemporaryDao.selectByMap( params , listRequest.getPageNum(), listRequest.getNumPerPage()); 
	        for(int i = 0; i< list.size(); i++) {
	        	FollowedShippingAddressWithAreaCode addr = list.get(i);
	        	parseFollowedAddressArea(addr);
	        }
	        
	        response.setList(list);
	        response.setPageTurn(list.getPageTurn());
	        response.setTip("未知用户收货地址查询成功");
	    } catch (Exception e) {
	    	log.error("func[{}] request[{}] exception[{}] desc[fail]",
					new Object[] { this.getClass().getName() +"."+Thread.currentThread().getStackTrace()[1].getMethodName(),
						request,Arrays.deepToString(e.getStackTrace()) });
			throw new ServiceOperationException("请求处理失败：" + e.getMessage());
		}
	    return response;
	}

	@Override
	public Response insertFollowedAddress(Request request) throws Exception {
		AddResponse<FollowedShippingAddressWithAreaCode> response = new AddResponse<FollowedShippingAddressWithAreaCode>();
    	
    	try {
	    	FollowedShippingAddressAddRequest addRequest = (FollowedShippingAddressAddRequest)request;
	    	FollowedShippingAddressWithAreaCode object = new FollowedShippingAddressWithAreaCode();
	    	object.setCity(addRequest.getCity());
	    	object.setContactNumber(addRequest.getContactNumber());
	    	object.setContacts(addRequest.getContacts());
	    	object.setDistrict(addRequest.getDistrict());
	    	object.setFullAddress(addRequest.getFullAddress());
	    	object.setIsPrivacyReceipt(addRequest.getIsPrivacyReceipt());
	    	object.setIsTemporaryAddress(addRequest.getIsTemporaryAddress());
	    	object.setPostcode(addRequest.getPostcode());
	    	object.setProvince(addRequest.getProvince());
	    	object.setRank(addRequest.getRank());
	    	object.setStatus(addRequest.getStatus());
	    	object.setStreet(addRequest.getStreet());
	    	object.setUserId(addRequest.getUserId());
	    	object.setAreaId(addRequest.getAreaId());
	    	object.setTelNumber(addRequest.getTelNumber());
	    	object.setName(addRequest.getName());
	    	
	    	FollowedShippingAddressWithAreaCode address = getDefaultFollowedAddress(addRequest.getUserId());
	    	if(null == address || address.getIsDefault() == ShippingAddressStatusEnum.STATUS_NOT_DEFAULT.getId()) {
	    		object.setIsDefault(ShippingAddressStatusEnum.STATUS_DEFAULT.getId());
	    	} else {
	    		object.setIsDefault(addRequest.getIsDefault());
	    	}
	    	
	    	userShippingAddressTemporaryDao.insert(object);
	    	response.setInfo(object);
	    	response.setTip("未知用户收货地址新增成功");
	    } catch (Exception e) {
	    	log.error("func[{}] request[{}] exception[{}] desc[fail]",
					new Object[] { this.getClass().getName() +"."+Thread.currentThread().getStackTrace()[1].getMethodName(),
						request,Arrays.deepToString(e.getStackTrace()) });
			throw new ServiceOperationException("请求处理失败：" + e.getMessage());
		}
	    return response;

	}

	@Override
	public Response deleteFollowedAddress(Request request) throws Exception {
	   	DeleteResponse<UserShippingAddressTemporary> response = new DeleteResponse<UserShippingAddressTemporary>();
    	int isDeleteDefault = ShippingAddressStatusEnum.STATUS_NOT_DEFAULT.getId();
    	
    	try {
	    	FollowedShippingAddressDeleteRequest deleteRequest = (FollowedShippingAddressDeleteRequest)request;
	    	FollowedShippingAddressWithAreaCode object = userShippingAddressTemporaryDao.selectById(deleteRequest.getId());
	    	if(!object.getUserId().equals(deleteRequest.getUserId())){
	    		throw new RequestIllegalException("非法操作，该地址非当前用户所有！userId" + deleteRequest.getUserId());
	    	}
	    	
	    	isDeleteDefault = object.getIsDefault(); 
	    	object.setStatus(ShippingAddressStatusEnum.STATUS_DELETE.getId());
	    	userShippingAddressTemporaryDao.update(object);
	    	
	    	//删除的地址如果为默认地址，默认将第一个
	    	if(isDeleteDefault == ShippingAddressStatusEnum.STATUS_DEFAULT.getId()) {
		    	Map<String,Object> params = new HashMap<String,Object>();
		    	params.put("eqUserId", deleteRequest.getUserId());
		    	params.put("eqStatus", ShippingAddressStatusEnum.STATUS_NOT_DELETE.getId());
		    	
		    	PageList<FollowedShippingAddressWithAreaCode> addressList = userShippingAddressTemporaryDao.selectByMap(params, 1, 1);
		    	if(null != addressList && addressList.size() > 0) {
		    		params.clear();
		    		params.put("eqId", addressList.get(0).getId());
		    		params.put("isDefault",ShippingAddressStatusEnum.STATUS_DEFAULT.getId());
			    	userShippingAddressTemporaryDao.updateByMap(params);
		    	 }
	    	}
	    	
	    	response.setTip("未知用户收货地址删除成功");
	    } catch (Exception e) {
	    	log.error("func[{}] request[{}] exception[{}] desc[fail]",
					new Object[] { this.getClass().getName() +"."+Thread.currentThread().getStackTrace()[1].getMethodName(),
						request,Arrays.deepToString(e.getStackTrace()) });
			throw new ServiceOperationException("请求处理失败：" + e.getMessage());
		}
	    return response;

	}

	@Override
	public Response updateFollowedAddress(Request request) throws Exception {
		UpdateResponse<UserShippingAddressTemporary> response = new UpdateResponse<UserShippingAddressTemporary>();
    	
    	try {
	    	FollowedShippingAddressUpdateRequest updateRequest = (FollowedShippingAddressUpdateRequest)request;
	    	FollowedShippingAddressWithAreaCode object = userShippingAddressTemporaryDao.selectById(updateRequest.getId());
	    	//修改地址以后将地址归类为官网地址
	    	if(!object.getUserId().equals(updateRequest.getUserId())){
	    		throw new RequestIllegalException("error userId:"+updateRequest.getUserId());
	    	}
	    	
	    	//object.setSource(OrderProduceSourceEnum.EHY.getCode());
	    	object.setId(updateRequest.getId());
	    	object.setCity(updateRequest.getCity());
	    	object.setContactNumber(updateRequest.getContactNumber());
	    	object.setContacts(updateRequest.getContacts());
	    	object.setDistrict(updateRequest.getDistrict());
	    	object.setFullAddress(updateRequest.getFullAddress());
	    	object.setIsDefault(updateRequest.getIsDefault());
	    	object.setIsPrivacyReceipt(updateRequest.getIsPrivacyReceipt());
	    	object.setIsTemporaryAddress(updateRequest.getIsTemporaryAddress());
	    	object.setPostcode(updateRequest.getPostcode());
	    	object.setProvince(updateRequest.getProvince());
	    	object.setRank(updateRequest.getRank());
	    	object.setStatus(updateRequest.getStatus());
	    	object.setStreet(updateRequest.getStreet());
	    	object.setUserId(updateRequest.getUserId());
	    	object.setAreaId(updateRequest.getAreaId());
	    	object.setTelNumber(updateRequest.getTelNumber());
	    	object.setName(updateRequest.getName());
	    	
	    	userShippingAddressTemporaryDao.update(object);
	    	response.setInfo(object);
	    	response.setTip("未知用户收货地址修改成功");
	    } catch (Exception e) {
	    	log.error("func[{}] request[{}] exception[{}] desc[fail]",
					new Object[] { this.getClass().getName() +"."+Thread.currentThread().getStackTrace()[1].getMethodName(),
						request,Arrays.deepToString(e.getStackTrace()) });
			throw new ServiceOperationException("请求处理失败：" + e.getMessage());
		}
	    return response;
	}
   
}